package org.summer.lawyer.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.summer.common.core.domain.R;
import org.summer.common.core.validate.AddGroup;
import org.summer.common.core.validate.EditGroup;
import org.summer.common.excel.utils.ExcelUtil;
import org.summer.common.idempotent.annotation.RepeatSubmit;
import org.summer.common.log.annotation.Log;
import org.summer.common.log.enums.BusinessType;
import org.summer.common.mybatis.core.page.PageQuery;
import org.summer.common.mybatis.core.page.TableDataInfo;
import org.summer.common.web.core.BaseController;
import org.summer.lawyer.domain.bo.payorder.PayOrderBo;
import org.summer.lawyer.domain.vo.payorder.PayOrderVo;
import org.summer.lawyer.service.IPayOrderService;

import java.util.List;

/**
 * 支付订单
 *
 * @author summer
 * @date 2024-06-22
 */
@Tag(name = "后台相关接口", description = "支付订单")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lawyer/payOrder")
public class PayOrderController extends BaseController {

    private final IPayOrderService payOrderService;

    /**
     * 查询支付订单列表
     */
    @Operation(summary = "查询支付订单列表接口", description = "查询支付订单列表", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("pay:order:list")
    @GetMapping("/list")
    public TableDataInfo<PayOrderVo> list(PayOrderBo bo, PageQuery pageQuery) {
        return payOrderService.selectPageList(bo, pageQuery);
    }

    /**
     * 导出支付订单列表
     */
    @Operation(summary = "导出支付订单列表接口", description = "导出支付订单列表")
    @SaCheckPermission("pay:order:export")
    @Log(title = "支付订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayOrderBo bo, HttpServletResponse response) {
        List<PayOrderVo> list = payOrderService.selectPayOrderVoList(bo);
        ExcelUtil.exportExcel(list, "支付订单", PayOrderVo.class, response);
    }

    /**
     * 获取支付订单详细信息
     *
     * @param id 主键
     */
    @Operation(summary = "获取支付订单详细信息接口", description = "查询支付订单列表", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckLogin
    //@SaCheckPermission("pay:order:query")
    @GetMapping("/{id}")
    public R<PayOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long id) {
        return R.ok(payOrderService.selectPayOrderVoById(id));
    }

    /**
     * 新增支付订单
     */
    @Operation(summary = "新增支付订单接口", description = "新增支付订单", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("pay:order:add")
    @Log(title = "支付订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/savePayOrder")
    public R<Void> savePayOrder(@Validated(AddGroup.class) @RequestBody PayOrderBo bo) {
        return toAjax(payOrderService.insertByBo(bo));
    }

    /**
     * 修改支付订单
     */
    @Operation(summary = "修改支付订单接口", description = "修改支付订单", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("pay:order:edit")
    @Log(title = "支付订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/updatePayOrder")
    public R<Void> updatePayOrder(@Validated(EditGroup.class) @RequestBody PayOrderBo bo) {
        return toAjax(payOrderService.updateByBo(bo));
    }

    /**
     * 删除支付订单
     *
     * @param ids 主键串
     */
    @Operation(summary = "删除支付订单接口", description = "删除支付订单", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("pay:order:remove")
    @Log(title = "支付订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/removePayOrder/{ids}")
    public R<Void> removePayOrder(@NotEmpty(message = "主键不能为空")
                                  @PathVariable Long[] ids) {
        return toAjax(payOrderService.deleteWithValidByIds(List.of(ids), true));
    }
}
